/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = '';
  
  checkConfig(config);
  @endpoint = getEndpoint('dbfs-ops', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model GetDbfsServerMetricRequest {
  from?: long(name='From'),
  pageNumber?: long(name='PageNumber'),
  pageSize?: long(name='PageSize'),
  queryString?: string(name='QueryString'),
  regionId?: string(name='RegionId'),
  sortType?: string(name='SortType'),
  to?: long(name='To'),
}

model GetDbfsServerMetricResponseBody = {
  metrics?: map[string]any(name='Metrics'),
  requestId?: string(name='RequestId'),
}

model GetDbfsServerMetricResponse = {
  headers: map[string]string(name='headers'),
  body: GetDbfsServerMetricResponseBody(name='body'),
}

async function getDbfsServerMetricWithOptions(request: GetDbfsServerMetricRequest, runtime: Util.RuntimeOptions): GetDbfsServerMetricResponse {
  Util.validateModel(request);
  var query = {};
  query['From'] = request.from;
  query['PageNumber'] = request.pageNumber;
  query['PageSize'] = request.pageSize;
  query['QueryString'] = request.queryString;
  query['RegionId'] = request.regionId;
  query['SortType'] = request.sortType;
  query['To'] = request.to;
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
    body = Util.toMap(request),
  };
  var params = new OpenApi.Params{
    action = 'GetDbfsServerMetric',
    version = '2021-07-21',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function getDbfsServerMetric(request: GetDbfsServerMetricRequest): GetDbfsServerMetricResponse {
  var runtime = new Util.RuntimeOptions{};
  return getDbfsServerMetricWithOptions(request, runtime);
}

model OperateResourceRequest {
  data?: string(name='Data'),
  regionId?: string(name='RegionId'),
}

model OperateResourceResponseBody = {
  requestId?: string(name='RequestId'),
  result?: string(name='Result'),
}

model OperateResourceResponse = {
  headers: map[string]string(name='headers'),
  body: OperateResourceResponseBody(name='body'),
}

async function operateResourceWithOptions(request: OperateResourceRequest, runtime: Util.RuntimeOptions): OperateResourceResponse {
  Util.validateModel(request);
  var query = {};
  query['Data'] = request.data;
  query['RegionId'] = request.regionId;
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
    body = Util.toMap(request),
  };
  var params = new OpenApi.Params{
    action = 'OperateResource',
    version = '2021-07-21',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function operateResource(request: OperateResourceRequest): OperateResourceResponse {
  var runtime = new Util.RuntimeOptions{};
  return operateResourceWithOptions(request, runtime);
}

model UploadFileRequest {
  data?: string(name='Data'),
  regionId?: string(name='RegionId'),
  body?: readable(name='body'),
}

model UploadFileResponseBody = {
  requestId?: string(name='RequestId', description='Id of the request'),
  result?: readable(name='result'),
}

model UploadFileResponse = {
  headers: map[string]string(name='headers'),
  body: UploadFileResponseBody(name='body'),
}

async function uploadFileWithOptions(request: UploadFileRequest, runtime: Util.RuntimeOptions): UploadFileResponse {
  Util.validateModel(request);
  var query = {};
  query['Data'] = request.data;
  query['RegionId'] = request.regionId;
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
    body = Util.toMap(request),
    stream = request.body,
  };
  var params = new OpenApi.Params{
    action = 'UploadFile',
    version = '2021-07-21',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function uploadFile(request: UploadFileRequest): UploadFileResponse {
  var runtime = new Util.RuntimeOptions{};
  return uploadFileWithOptions(request, runtime);
}

